/* GUI CONVERTED from woworle.p (converter v1.75) Sat Aug 12 16:39:13 2000 */
/* woworle.p - SCHEDULE WORK ORDER OPERATIONS                           */
/* Copyright 1986-2000 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                   */
/*J23R*/ /*V8:WebEnabled=No                                             */
/* REVISION: 1.0     LAST MODIFIED: 06/18/86    BY: EMB                 */
/* REVISION: 2.0     LAST MODIFIED: 09/01/87    BY: EMB *A85*           */
/* REVISION: 4.0     LAST MODIFIED: 01/05/89    BY: EMB *A584*          */
/* REVISION: 5.0     LAST MODIFIED: 01/23/90    BY: EMB *B527*          */
/* REVISION: 6.0     LAST MODIFIED: 05/11/90    BY: RAM *D018*          */
/* REVISION: 7.0     LAST MODIFIED: 04/03/92    BY: RAM *F355*          */
/* REVISION: 7.0     LAST MODIFIED: 05/24/95    BY: qzl *F0S4*          */
/* REVISION: 7.4     LAST MODIFIED: 12/20/97    BY: *H1HK* Felcy D'Souza*/
/* REVISION: 8.6     LAST MODIFIED: 02/27/98    BY: *J23R* Santhosh Nair */
/* REVISION: 8.6E    LAST MODIFIED: 08/05/98    BY: *H1H4* Dana Tunstall */
/* REVISION: 9.1     LAST MODIFIED: 08/12/00    BY: *N0KC* myb           */

         {mfdeclre.i}

         define shared variable wo_recno as recid.
         define new shared variable last_due as date.
         define new shared variable last_op like wr_op.
         define new shared variable allow_queue as integer.

/*H1H4*/ define new shared temp-table temp-wr_route no-undo like wr_route
             use-index wr_lot.

/*H1HK*/ define variable any-routings like mfc_logical initial no no-undo.
/*H1HK*/ define variable leadtime     like pt_mfg_lead no-undo.

/*H1HK*/ {mfdatev.i}



         /*J23R*find*/ for first wo_mstr
/*J23R*/ fields(wo_due_date wo_lot wo_rel_date wo_part wo_site)
     where recid(wo_mstr) = wo_recno no-lock /*no-error*/: end.
         if not available wo_mstr then leave.

         allow_queue = 1.
/*F0S4*  last_due = wo_due_date. */
         last_op = 999999.



         for each wr_route
/*J23R*/ fields(wr_lot wr_op wr_status)
     no-lock where wr_lot = wo_lot
            by wr_lot descending by wr_op descending:

/*H1HK*/    any-routings = yes.

            if wr_status = "C" then leave.
            last_op = wr_op.
         end.
         


/*H1HK*  BEGIN OF ADDED SECTION */
/*       IF THE ORDER HAS NO ROUTING RECORDS AND EITHER THE RELEASE   */
/*       OR THE DUE DATE IS UNKNOWN, THE SPREAD IS CALCULATED BETWEEN */
/*       THE RELEASE AND DUE DATE BY USING THE MANUFACTURING LEAD TIME*/
/*       OF THE ITEM/SITE INSTEAD OF SCHEDULING THE OPERATIONS. */

         if any-routings = no and
            (wo_rel_date = ? or wo_due_date = ?)
         then do:

            /*J23R*find*/ for first ptp_det
/*J23R*/     fields(ptp_mfg_lead ptp_part ptp_site)
        where ptp_part = wo_part
                           and ptp_site = wo_site
                 no-lock /*no-error*/: end.

            if available ptp_det then
        leadtime = ptp_mfg_lead.

            else do:

               /*J23R*find*/ for first pt_mstr
/*J23R*/       fields(pt_mfg_lead pt_part)
           where pt_part = wo_part no-lock /*no-error*/: end.

               if available pt_mstr then
           leadtime = pt_mfg_lead.

            end. /* IF NOT AVAILABLE ptp_det */

            {mfdate.i wo_rel_date wo_due_date leadtime wo_site}

        end. /*IF any-routings */
        


/*H1HK*  END OF ADDED SECTION */

/*H1H4*/ /* Added section */
         /* Instead of rescheduling the DB tables themselves,
            create temp-table images of wr_route for the scheduling
            subroutines to work against.  When done, the DB tables
            will need to be re-synchronized against the rescheduled
            temp-tables (in woworleb.p). */
         if any-routings = yes then do:
         
            {gprun.i ""woworlea.p"" "(input wo_lot)"}
         
/*GUI*/ if global-beam-me-up then undo, leave.

         end.
/*H1H4*/ /* End of added section */


/*F0S4*/ /*********** Added: Begin *************************************/
         if wo_due_date <> ? then do:
            last_due = wo_due_date.
            /* SCHEDULE BACKWARDS FROM WORK ORDER DUE DATE */
/*H1H4*     {gprun.i ""woworle1.p""}  */

/*H1H4*/    {gprun.i ""woworle1.p""
               "(input wo_lot,
                 input wo_site,
                 input last_op,
                 input-output last_due)"}

/*GUI*/ if global-beam-me-up then undo, leave.


             if wo_rel_date = ? then wo_rel_date = last_due.
         end.
         else do:
            last_due = wo_rel_date.
            /* SCHEDULE FORWARDS FROM WORK ORDER RELEASE DATE */
/*H1H4*     {gprun.i ""woworle2.p""} */

/*H1H4*/    {gprun.i ""woworle2.p""
               "(input wo_lot,
                 input wo_site,
                 input last_op,
                 input-output last_due)"}

/*GUI*/ if global-beam-me-up then undo, leave.


            if wo_due_date = ? then wo_due_date = last_due.
         end.
/*F0S4*/ /*********** Added: End ***************************************/

/*H1H4*/ /* Added section */
         /* Re-synchronize the DB tables against the rescheduled temp-tables. */
         if any-routings = yes then do:

            {gprun.i ""woworleb.p"" "(input wo_lot)"}

/*GUI*/ if global-beam-me-up then undo, leave.

         end.
/*H1H4*/ /* End of added section */

/*F0S4*/ /************ Deleted: Begin ***********************************
/*D018 * if wo_due_date > today then do: */
       *
       *    /* SCHEDULE BACKWARDS FROM WORK ORDER DUE DATE */
       *    {gprun.i ""woworle1.p""}
/*F355 *    /* SCHEDULE FORWARD TO SMOOTH OPER DUE DATES */ */
/*F355 *    {gprun.i ""woworle2.p""}                        */
       *
/*D018 * end.
       *
       * if last_due > wo_due_date or wo_due_date <= today then do:
       *
       *    /* SCHEDULE BACKWARD & COMPRESS QUEUE TO ZERO */
       *    allow_queue = 0.
       *    last_due = wo_due_date.
       *    {gprun.i ""woworle1.p""}
       *    {gprun.i ""woworle2.p""}
       *
       * end.
  D018*/
/*F0S4*/ ************* Deleted: End *************************************/
